﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using OgilvyOne.UKNow.Model;
using ECCIT.Data;
namespace OgilvyOne.UKNow.DAL
{
   public class MemberMappDAL
    {
       string dtName = "UKNOW_MEMBER_ACCOUNT_MAPPING";
       string Mapid = "COL_MAPPING_ID";
       string Mtype = "COL_EX_MEMBER_TYPE";
       string Exid = "COL_EX_MEMBER_ID";
       string UKid = "COL_IN_MEMBER_ID";
       //添加映射关系
       public bool add(MemberMappMod mm)
       {
           string sqlcmd = String.Format(
               "insert into {0} ({1},{2},{3}) values({4},'{5}',{6})",
                dtName,
                Mtype,
                Exid,
                UKid,
                mm.Mtype.ToString(),
                mm.Exid,
                mm.UKid.ToString());
                
           return DBHelper.ExecuteNonQuery(sqlcmd)>0?true:false;
       }
       //判断是否存在映射关系
       public bool isExit(string eid)
       {
           string sqlcmd = String.Format("select count({0}) as  res   from   {1} where {2}='{3}' ", Mapid, dtName, Exid, eid);
           return DBHelper.ExecuteDataSet(sqlcmd,null).Tables[0].Rows[0]["res"].ToString()!="0"?true:false;
       }
       //返回ukid
       public int? getUkid(string eid)
       {
           string sqlcmd = String.Format("select {0} as res from {1} where {2}='{3}'",UKid,dtName,Exid,eid);
           string res= DBHelper.ExecuteDataSet(sqlcmd,null).Tables[0].Rows[0]["res"].ToString();
           if (res != null && res != "")
           {
               return int.Parse(res);

           }
           else
           {
               return null;
           }
           
       }

    }

}
